
CREATE PROC SP_MIGRATION_OF_SHIPING_ADDRESS

  @END_CUSTOMER_ID INT,  
  @SHIP_ADDRESS1 VARCHAR(50),
  @SHIP_ADDRESS2 VARCHAR(50),
  @SHIP_ADDRESS3 VARCHAR(50),
  @SHIP_ADDRESS4 VARCHAR(50),

  @SHIP_CITY VARCHAR(50),
  @SHIP_STATE VARCHAR(50),
  @SHIP_ZIP VARCHAR(50),
  @SHIP_COUNTRY VARCHAR(50),
  @ERROR_CODE VARCHAR(200) OUTPUT
AS

BEGIN	
	DECLARE @DB_SHIP_ADDRESS_ID INT	
	
	IF ( @END_CUSTOMER_ID > 0 ) 
	BEGIN
		-- Insertion of shipping address
		INSERT INTO ADDRESS ( ADDRESS_1, ADDRESS_2, ADDRESS_3, ADDRESS_4, CITY, STATE, ZIPCODE, COUNTRY  ) VALUES ( @SHIP_ADDRESS1, @SHIP_ADDRESS2 , @SHIP_ADDRESS3, @SHIP_ADDRESS4 , @SHIP_CITY , @SHIP_STATE , @SHIP_ZIP , @SHIP_COUNTRY  )
			SET @DB_SHIP_ADDRESS_ID = ( SELECT @@IDENTITY )
		INSERT INTO CUSTOMER_SHIPPING_ADDRESS_TABLE ( CUSTOMER_ID, ADDRESS_ID, TIMESTAMP ) VALUES ( @END_CUSTOMER_ID, @DB_SHIP_ADDRESS_ID, CURRENT_TIMESTAMP )
		SET @ERROR_CODE = 'shipping address saved successfully'
	END
	ELSE
	BEGIN
		SET @ERROR_CODE = 'Invalid End customer Id'
	END

END
